/***********************************************************************************************//**
 * \file   connection-callback.c
 * \brief  Callbacks related to connection
 ***************************************************************************************************
 * <b> (C) Copyright 2015 Silicon Labs, http://www.silabs.com</b>
 ***************************************************************************************************
 * This file is licensed under the Silabs License Agreement. See the file
 * "Silabs_License_Agreement.txt" for details. Before using this software for
 * any purpose, you must agree to the terms of that agreement.
 **************************************************************************************************/
#include CONFIGURATION_HEADER


/* standard library headers */
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>

/* serial retarget for cable replacement */
#if !defined HOST && (defined SILABS_AF_PLUGIN_CABLE_SERVER || defined SILABS_AF_PLUGIN_CABLE_CLIENT)
#include "retargetserial.h"
#endif /* !defined HOST && (defined SILABS_AF_PLUGIN_CABLE_SERVER || defined SILABS_AF_PLUGIN_CABLE_CLIENT) */

/* application specific headers*/
#include "app_ui.h"

/* Own header*/
#include "connection-callback.h"

/***************************************************************************************************
  Local Macros and Definitions
***************************************************************************************************/

/* Text definitions*/
#define CON_HTMKYFOB_CONN_TEXT       "\nConnected\n\n"

/***************************************************************************************************
 Function Definitions
 **************************************************************************************************/

void connectionOpenedEventCallback(void)
{
  appUiWriteString(CON_HTMKYFOB_CONN_TEXT); /* Display Connected state */
  
#if !defined HOST && defined SILABS_AF_PLUGIN_CABLE_SERVER
  /* Send diagnostic data to serial port in ASCII - Connection is established */
  printf("Connected\n");
#endif /* !defined HOST && defined SILABS_AF_PLUGIN_CABLE_SERVER */

#if !defined HOST && defined SILABS_AF_PLUGIN_CABLE_CLIENT
  /* Connection has been established with server */
  /* Send diagnostic data to serial port in ASCII */
  printf("Connected to "SILABS_AF_PLUGIN_CENTRAL_TARGET_DEV_NAME);
  printf("\nDiscovering services... \n");
#endif /* !defined HOST && defined SILABS_AF_PLUGIN_CABLE_SERVER */
}

void connectionTerminatedEventCallback(void)
{
  appUiLedOff();

#if !defined HOST && defined SILABS_AF_PLUGIN_CABLE_SERVER
  /* Send diagnostic data to serial port in ASCII - Connection has been closed or dropped */
  printf("\nDisconnected\n");
#endif /* !defined HOST && defined SILABS_AF_PLUGIN_CABLE_SERVER */

#if !defined HOST && defined SILABS_AF_PLUGIN_CABLE_CLIENT
  /* Connection has been closed or lost */
  printf("\nDisconnected\n");
  printf("Scanning...\n");
  
#endif /* !defined HOST && defined SILABS_AF_PLUGIN_CABLE_SERVER */
}


